package com.dp;

public class Solution30 {
    public int robAct(int[] nums,int start,int end) {
        int pre = 0;
        int cur = nums[start];
        int res = nums[start];
        for (int i = start+1; i < end; i++) {
            res = Math.max(cur, pre + nums[i]);
            pre = cur;
            cur = res;
        }
        return res;
    }

    public int rob(int[] nums) {
        if (nums== null || nums.length == 0) return 0;
        if (nums.length == 1) return nums[0];
        return Math.max(robAct(nums,1,nums.length),robAct(nums,0, nums.length-1));
    }
}
